<template>
    <div class="main">
        <div id="doctorDorp" v-show="isShowImg">
            <!--<img src="../../images/backDoc.png" />-->
        </div>
    </div>
</template>
<script>
import { getCookie ,setCookie,compareObj,setSelectedApp,getAppName,getAppEName,getAppID} from '../../config/mUtils'
import { getAgentInfoReturn,getAppsubject,setLastApp } from "../../config/getData"
import { getAgentCode ,getAgentUrl} from "../../config/agent"
import {G_agentUrl} from '../../config/global'
export default {
    data: function() {
        return {
            isShowImg: false,    // 是否显示登录
            getAgent:null  //获取代理商信息
        }
    },
    methods: {
        async jumpUrl() {
        	var _that = this;
        	this.checkbrowser();
            let url = localStorage.getItem('guid');
        	var agentCode = _that.$route.query.ac;
			var agentUrl = G_agentUrl;
			if(agentCode) { //带有代理商参数，拼接url
				agentUrl = agentUrl + '/?ac=' + agentCode;
			} 
			if(!agentCode) {
				agentCode = '';
			}
			var en = _that.$route.query.en;
			var token = _that.$route.query.token;
			var vn = _that.$route.query.vn;
			if(!vn){
				vn = 0;
			}
			getAgentCode().then(res=>{
				let agentCodeNew = res;
				setCookie('AGENTCODE',res);
				getAgentUrl().then(res=>{
					setCookie('AGENTURL',res);
					if(en&&token){
						_that.specifyAppEName(en,vn,token)
					}else{
						if(getAppName()&&getAppEName()&&getAppID()){
		//					this.$router.push('/selectsub');
						}else{
							this.$router.push('/login?ac='+agentCodeNew);
						}
					}
				})
			});
//			getAgentInfoReturn(agentUrl,agentCode).then(res => {
//				let agentInfo = res.data.agentInfo;
//              setCookie('AGENTCODE',agentInfo.AgentCode);
//              setCookie('AGENTURL',agentInfo.AgentUrl);
//              sessionStorage.setItem('agentInfo', JSON.stringify(agentInfo));
//			})
			
//          let res = this.getAgent;
//          console.log( getAgentInfo())
//          if (res.status === 200) {
//          	let agentInfo = res.data.agentInfo;
//          } else if (res.status === 201) {
//              
//          }
//          if (url) {
//              this.$router.push('/selectsub');
//              return;
//          }else{
//          	this.$router.push('/login');
//          }
//          this.isShowImg = true;
        }, 
   		specifyAppEName: function(en,vn,guid){
   			getAppsubject(en,vn,guid,1).then(res=>{
   				if(res.status === 200){
   					let dataJson ={};
   					var jsonData = res.data;
					for(let key in jsonData){
			            if(key!=='ar'){
			            	dataJson['has'+ key] = 1
			            }
			        }
	            	let verData = jsonData.ar.sort(compareObj("vnorder"));
	            	let maxVerData = verData[verData.length - 1];
	                if (maxVerData.vn === 2) {
	                    maxVerData = verData[verData.length - 2];
	                }
	                
	                setSelectedApp(maxVerData.CName, maxVerData.AppEName, maxVerData.AppID)
	                localStorage.setItem('guid',guid);
//	                G_Cookie.setSelectedApp(name, dataNew.AppEName, dataNew.AppID, dataNew.AppEName); //存储选择的科目信息
//	                if(index){
//		                G_Prg.setCookie('VerName', dataNew.vname);
//		                var operJson = {};
//		                operJson.VerNO = dataNew.vn; //版本编号
//		                operJson.VerJSON = dataJson; //版本功能配置json
//		                operJson.VerName = dataNew.vname;
//		                G_Prg.setCookie('AppVerOperJSON', JSON.stringify(operJson));
//		                _getAppENameJump(_appID,dataNew.vn,dataNew.AppEName);
//	                }else{
		                var operJson = {};
		                operJson.VerNO = maxVerData.vn; //版本编号
		                operJson.VerJSON = dataJson; //版本功能配置json
		                operJson.VerName = maxVerData.vname;
		                setCookie('AppVerOperJSON', JSON.stringify(operJson));
		                this.getAppENameJump()
//	                }
   				}
   			})
   		},
   		getAppENameJump :function(){
   			setLastApp().then(res=>{
   				if(res.status===200){
// 					this.$router.push('/selectsub');
   				}
   			})
   		},
        checkbrowser: function(){
        	var Sys = {};
	        var ua = navigator.userAgent.toLowerCase();
	        var s;
	        (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
	                (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
	                        (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
	                                (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
	                                        (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
	
	        if (Sys.ie) {
	            if (!isNaN(parseInt(Sys.ie))) {
	                var version = parseInt(Sys.ie);
	                if (version <= 8) {
	                    if (document.location.href.indexOf('browser') < 0) {
	                    	return;
//	                        document.location.href = 'browser.html';
	                    }
	                }
	            }
	        }
        }
    },
    created: function(){
//      this.jumpUrl();
    },
    mounted:function(){
    	this.$nextTick(()=>{
	        this.jumpUrl();
	    });
    	 
    }
}

</script>
<style scoped lang="less">
#doctorDorp {
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    background: #999;
    z-index: 100000;
    img {
        width: 75%;
        margin: 5px 0 0 20px;
    }
}
</style>